package hrm.action.insa;

import hrm.action.Action;
import hrm.action.ActionForward;
import hrm.dto.insa.EducationDTO;
import hrm.dto.insa.EmployeeDTO;
import hrm.dto.insa.FamilyDTO;
import hrm.dto.insa.LanguageDTO;
import hrm.dto.insa.LicenceDTO;
import hrm.dto.insa.MilitaryDTO;
import hrm.dto.login.LoginDTO;
import hrm.serviceimple.EducationServiceImple;
import hrm.serviceimple.EmployeeServiceImple;
import hrm.serviceimple.FamilyServiceImple;
import hrm.serviceimple.LanguageServiceImple;
import hrm.serviceimple.LicenceServiceImple;
import hrm.serviceimple.MilitaryServiceImple;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InsaAllViewAction implements Action {

	@SuppressWarnings("unchecked")
	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		ActionForward actfoward = new ActionForward();
		
		EmployeeServiceImple employeeService = EmployeeServiceImple.getInstance();
		EmployeeDTO employeeDTO = new EmployeeDTO();
		employeeDTO.setId(getFindId(request));
		employeeDTO = employeeService.getEmployee(employeeDTO);	

		LanguageServiceImple languageService = LanguageServiceImple.getInstance();
		LanguageDTO languageDTO = new LanguageDTO();
		languageDTO.setId(getFindId(request));
		List<LanguageDTO> langList = languageService.getAllLanguage(languageDTO);	
		
		EducationServiceImple educationService = EducationServiceImple.getInstance();
		EducationDTO edto = new EducationDTO();
		edto.setId(getFindId(request));
		List<EducationDTO> educationList = educationService.getEducation(edto);
		
		FamilyServiceImple familyService = FamilyServiceImple.getInstance();
		FamilyDTO dto = new FamilyDTO();
		dto.setId(getFindId(request));
		List<FamilyDTO> FamilyList = familyService.getFamily(dto);
		
		LicenceServiceImple licenceService = LicenceServiceImple.getInstance();
		LicenceDTO ldto =  new LicenceDTO();
		ldto.setId(getFindId(request));
		List<LicenceDTO> licenceList = licenceService.getAllLicence(ldto);
		
		MilitaryServiceImple militaryService = MilitaryServiceImple.getInstance();
		MilitaryDTO militaryDTO = new MilitaryDTO();
		militaryDTO.setId(getFindId(request));
		List<MilitaryDTO> militaryList = militaryService.getAllMilitary(militaryDTO);	

		request.setAttribute("employeeDTO", employeeDTO);
		request.setAttribute("langList", langList);
		request.setAttribute("educationlist", educationList);
		request.setAttribute("FamilyList", FamilyList);
		request.setAttribute("licencelist", licenceList);
		request.setAttribute("militaryList", militaryList);
		
		actfoward.setUrl("listAll");	
		return actfoward;
	}

	private String getFindId(HttpServletRequest request) {
		String findid = (String)request.getSession().getAttribute("findid");
		if(findid == null){
			findid = ((LoginDTO)request.getSession().getAttribute("login")).getId();
			request.setAttribute("findid", findid);
		}
		return findid;
	}
}
